
var moment = require('moment');

module.exports = {
	
	getMonthByAction : function(month,action){
		
		month = month ? month : moment().format("YYYYMM");
		var current = moment(month+'01 000000', 'YYYYMMDD HHmmss');
		if(action == "prev"){
			current = current.subtract(1, 'months');
		}else if(action == "next"){
			current = current.add(1, 'months');
		}
		var next = current.clone().add(1, 'months');
		
		return {
			current : current,
			next : next
		}
	},
	
	getYearByAction : function(year,action){
		
		year = year ? year : moment().format("YYYY");
		var current = moment(year+'0101 000000', 'YYYYMMDD HHmmss');
		
		if(action == "prev"){
			current = current.subtract(1, 'years');
		}else if(action == "next"){
			current = current.add(1, 'years');
		}
		var next = current.clone().add(1, 'years');
		
		return {
			current : current,
			next : next
		}
	},
	
	getDay : function(date,action){
		
		date = date ? date : moment().format("YYYYMMDD");
		var current = moment(date+' 000000', 'YYYYMMDD HHmmss');
		
		if(action == "prev"){
			current = current.subtract(1, 'days');
		}else if(action == "next"){
			current = current.add(1, 'days');
		}
		var next = current.clone().add(1, 'days');
		
		return {
			current : current,
			next : next
		}
	}
	
}